import { Component, OnInit } from '@angular/core';
import { NavController } from '@ionic/angular';
import { ActivatedRoute, Params } from '@angular/router';
import * as constants from 'src/app/providers/Constants'
import { Router } from '@angular/router';
import { ShopService } from 'src/app/services/shop.service';
import { ToastService } from 'src/app/providers/toast/toast.service';
import { Storage } from 'src/app/providers/Storage';

@Component({
  selector: 'app-collect-list',
  templateUrl: './collect-list.page.html',
  styleUrls: ['./collect-list.page.scss'],
})
export class CollectListPage implements OnInit {
  categoryDetailData:any=[];
  imageUrl:string='';
  constructor(private nav: NavController, private activeRoute: ActivatedRoute, public service: ShopService, private toast: ToastService) {
    this.imageUrl=this.service.getImageUrl();
   }

  ngOnInit() {
  }
  ionViewDidEnter() {
    this.getList();

  }



  onItemDetail(info){
    this.nav.navigateForward(['/goods-details'], {
      queryParams: {
        shopInfo: JSON.stringify(info)
      }
    });
  }

  AmountOfConversion(num: number) {
    return num / 100;
  }
  getList() {
    this.service.getSelProcCollect({}).subscribe(res => {
      // 保存成功返沪上一页，否则弹出提示框
      if (res.retCode == '000000') {
        res.array.forEach(element => {
          element.procImg =this.imageUrl + element.procImg.split(',')[0];
        });
        this.categoryDetailData = res.array;
      } else if (constants.errCode[res.retCode]) {
        if (constants.errCode[res.retCode] != '0') {
          this.toast.show(constants.errCode[res.retCode]);
        }
      } else if (res.retMsg) {
        this.toast.show(res.retMsg);
      } else {
        this.toast.show("exception service routine");
      }
    });
  }
}
